package gui;

import gui.drawers.*;

import javax.swing.*;

import dal.MapStruct;

import java.awt.*;

@SuppressWarnings("serial")
public class LayeredPane extends JPanel {
	private JLayeredPane layeredPane;
	protected GroundDrawer groundDrawer;
	protected RockDrawer rockDrawer;
	protected BallDrawer ballDrawer;
	protected ShadowDrawer shadowDrawer;
	protected ToolDrawer toolDrawer;
	protected HoverDrawer hoverDrawer;
	private Point start;
	
	public JLayeredPane getJLayeredPane(){
		return layeredPane;
	}
	
	public LayeredPane(MapStruct ms) {
		setLayout(new GridBagLayout());
		
		groundDrawer = new GroundDrawer(ms);
		toolDrawer = new ToolDrawer(ms);
		rockDrawer = new RockDrawer(ms);
		shadowDrawer = new ShadowDrawer(ms);
		ballDrawer = new BallDrawer(ms, shadowDrawer);
		hoverDrawer = new HoverDrawer(ms);
		
		layeredPane = new JLayeredPane();
		layeredPane.setPreferredSize(ms.getSize());
		setSize(ms.getSize());
		layeredPane.add(rockDrawer);
		layeredPane.add(toolDrawer);
		layeredPane.add(ballDrawer);
		layeredPane.add(shadowDrawer);
		layeredPane.add(groundDrawer);
		layeredPane.add(hoverDrawer);
		layeredPane.setLayer(hoverDrawer, GameConstants.HOVER_LAYER);
		layeredPane.setLayer(rockDrawer, GameConstants.ROCK_LAYER);
		layeredPane.setLayer(toolDrawer, GameConstants.TOOL_LAYER);
		layeredPane.setLayer(shadowDrawer, GameConstants.SHADOW_LAYER);
		layeredPane.setLayer(ballDrawer, GameConstants.BALL_LAYER);
		layeredPane.setLayer(groundDrawer, GameConstants.GROUND_LAYER);
		
		this.start = ms.getUpperLeftCorner();
		this.setLocation(start.x, start.y);
		
		add(layeredPane);
	}
	
	/**
	 * sets this location to is's initial location
	 */
	public void restart(){
		this.setLocation(start.x, start.y);
		((MapViewPort) this.getParent()).initResizability();
	}
	
/*	public static void main(String[] args) {
		MapStruct ms = FileIO.loadFromFile(new File("map/my/4.amg"));
		MapViewPort mvp = new MapViewPort(new PlayersMap(ms != null ? ms : new MapStruct()));
		JComponent newContentPane = mvp;	
		newContentPane.setOpaque(false);
		
		try {
			new MainWindow("settings.dat");
		} catch (IOException e) {
			e.printStackTrace();
		} catch (AWTException e) {
			e.printStackTrace();
		}
		
		MainWindow.getMainWindow().setCenter();
		JFrame jf = new JFrame ("Amgine");
		newContentPane.setPreferredSize(new Dimension(800, 600)); // 640x480
		jf.setContentPane(newContentPane);
		jf.pack();
		jf.setLocationRelativeTo(null);
		jf.setVisible(true);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		try {
			Robot r = new Robot();
			r.mouseMove(MainWindow.getCenterX(), MainWindow.getCenterY());
		} catch (AWTException e) {
			e.printStackTrace();
		}
	}*/
}